/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86186
 * Date: 2023-06-25
 * Time: 21:45
 */
public class Test {
    public int canCompleteCircuit(int[] gas, int[] cost) {
        for(int i = 0; i < gas.length; i++) {
            int sum = gas[i] - cost[i];
            int j = (i+1) % gas.length;
            while(j % gas.length != i) {
                if(sum < 0) {
                    break;
                }
                sum = sum + gas[j] - cost[j];
                j = (j+1) % gas.length;
            }
            if(sum >= 0) {
                return i;
            }
        }

        return -1;
    }

}


